<template>
  <div>
    <p>请选择购买数量：</p>
    <div v-for="(item, index) in list" :key="index">
      {{ item.shopName }}
      <span><button @click="addFn(index)">+</button></span>
      <span>{{ item.count }}</span>
      <span><button @click="delFn(index)">-</button></span>
    </div>

    <p>总价为：{{ allPrice }}</p>
  </div>
</template>

<script>
export default {
  props: ["list"],
  methods: {
    addFn(ind) {
      this.list[ind]["count"]++;
    },
    delFn(ind) {
      this.list[ind]["count"] > 0 && this.list[ind]["count"]--;
    },
  },
  computed: {
    allPrice() {
      return this.list.reduce(
        (sum, item) => (sum += item.price * item.count),
        0
      );
    },
  },
};
</script>

<style>
</style>